<template>
  <div class="todo-footer">
    <label>
      <input 
        type="checkbox" 
        v-model="allCheck"
      />
    </label>
    <span> <span>已完成{{donecount}}</span> / 全部{{total}} </span>
    <button class="btn btn-danger" @click="cleartodo">清除已完成任务</button>
  </div>
</template>

<script>
export default {
  name: "Footer",
  props:['cleartododne','todos','checkAllTodo'],
  computed: {
    donecount(){
      // FIXME: 使用reduce做统计
      return this.todos.reduce((preValue,current)=>{
        return preValue + (current.done ? 1 : 0)
      },0)
    },
    total(){
      return this.todos.length;
    },
    allCheck:{
      get(){
        return (this.donecount === this.total) && this.total > 0;
      },
      set(val){
        //通知App去全选 or 全不选
					this.checkAllTodo(val)
      }
    }
  },
  methods: {
    cleartodo(){
      this.cleartododne()
    },
  },
};
</script>

<style scoped>
/*footer*/
.todo-footer {
  height: 40px;
  line-height: 40px;
  padding-left: 6px;
  margin-top: 5px;
}

.todo-footer label {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}

.todo-footer label input {
  position: relative;
  top: -1px;
  vertical-align: middle;
  margin-right: 5px;
}

.todo-footer button {
  float: right;
  margin-top: 5px;
}
</style>